package br.com.aquinoevasconcelos.servlets.cliente;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * Servlet implementation class SairCliente
 */
@WebServlet("/SairCliente")
public class SairCliente extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public SairCliente() {
		super();
	}

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

    	try {
			
    		
    		HttpSession sessaoCliente = request.getSession();
    		sessaoCliente.invalidate();
    		System.out.println("sessão Encerrada!!");
    		response.sendRedirect("Index");
    		
    		
		} catch (Exception e) {
			response.sendRedirect("pagina_erro/erro.jsp");
			e.printStackTrace();
		}
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

}
